package com.chenhao.spingcloud.chenhaoeurekauser.mapper;

import com.chenhao.spingcloud.chenhaoeurekauser.model.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Select({
            "select * from product"
    })
    List <Product> listAll();

    @Select({
            "select * from product where id = #{userId}"
    })
    Product getUserById(Integer userId);

    @Select({
            "select * from product where id = #{id} for update;"
    })
    Product selectForUpdate(Integer id);

    @Insert({
            "insert into product(`name`) values(#{name})"
    })
    int insert(Product user);

    @Delete({
            "delete from product where id = #{userId}"
    })
    int remove(Integer userId);

    @Update({
            "update product set username = #{username}, password = #{password} where id = #{id}"
    })
    int update(Product user);

    @Update({
            "update product set skill_num = #{skillNum} where id = #{id}"
    })
    int updateByid(Product user);


    @Update({
            "UPDATE product set skill_num = #{skillNum},version = #{version}+1 where id = #{id} and version = #{version}"
    })
    int pessimismLock(Product user);
}
